package org.example.commodity.activity.timertask;

import org.example.commodity.activity.entity.ActivityInfo;
import org.example.commodity.activity.timertask.processor.ICommodityActivityEndProcessor;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import lombok.extern.slf4j.Slf4j;

/**
 * 商品活动结束时间轮执行任务
 */
@Slf4j
public abstract class BaseCommodityActivityEndTimerTask<T extends ActivityInfo> implements TimerTask {

    private final Long activityId;
    private final ICommodityActivityEndProcessor<T> endProcessor;

    protected BaseCommodityActivityEndTimerTask(Long activityId,
                                                ICommodityActivityEndProcessor<T> endProcessor) {
        this.activityId = activityId;
        this.endProcessor = endProcessor;
    }

    @Override
    public void run(Timeout timeout) {
        log.info("商品活动{}结束任务开始执行", activityId);
        try {
            endProcessor.endActivity(activityId);
        }catch (Exception e){
            log.error("商品活动{}结束失败，{}", activityId,e.getMessage());
        }
        log.error("商品活动{}结束成功", activityId);
    }
}
